package com.bluefuture.modules.app.controller;

import com.bluefuture.common.utils.ResultVo;
import com.bluefuture.common.utils.ResultVoUtil;
import com.bluefuture.modules.app.service.CollectUserService;
import com.bluefuture.modules.app.service.UserService;
import com.bluefuture.modules.app.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author leo
 * @email leo_zhou@1234.com
 * @date 2022-03-05 19:45:21
 */
@RestController
@RequestMapping("app/collectuser")
@Api(tags = "APP用户收藏接口")
@Slf4j
public class CollectUserController {
    @Autowired
    private CollectUserService collectUserService;

    @Autowired
    private UserService userService;

    /**
     * 收藏列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "收藏用户列表")
    public ResultVo<List<UserVO>> list() {
        List<Integer> collectUserIds = collectUserService.listCollectUserIds();
        List<UserVO> result = userService.selectByIds(collectUserIds);

        return ResultVoUtil.success(result);
    }


//    /**
//     * 信息
//     */
//    @RequestMapping("/info/{id}")
//    public R info(@PathVariable("id") Integer id){
//		CollectUserEntity collectUser = collectUserService.getById(id);
//
//        return R.ok().put("collectUser", collectUser);
//    }

    /**
     * 保存
     */
    @GetMapping("/save")
    @ApiOperation(value = "收藏用户")
    public ResultVo save(@RequestParam("userId") Integer userId) {
        collectUserService.collect(userId);
        return ResultVoUtil.success();
    }

//    /**
//     * 修改
//     */
//    @RequestMapping("/update")
//    public R update(@RequestBody CollectUserEntity collectUser){
//		collectUserService.updateById(collectUser);
//
//        return R.ok();
//    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    @ApiOperation(value = "取消收藏用户")
    public ResultVo delete(@RequestParam("userId") Integer userId) {
        collectUserService.deleteCollectUser(userId);
        return ResultVoUtil.success();
    }

}
